package com.ruoyi.house.service.impl;

import com.ruoyi.house.domain.BusinessCircleEntity;
import com.ruoyi.house.domain.SysRegionEntity;
import com.ruoyi.house.mapper.BusinessCircleDao;
import com.ruoyi.house.mapper.dao.SysRegionDao;
import com.ruoyi.house.service.SysRegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service("sysRegionService")
public class SysRegionServiceImpl implements SysRegionService {
	@Autowired
	private SysRegionDao sysRegionDao;
	@Autowired
	private BusinessCircleDao businessCircleDao;
	
	@Override
	public SysRegionEntity queryObject(Integer regionId){
		return sysRegionDao.queryObject(regionId);
	}
	
	@Override
	public List<SysRegionEntity> queryList(Map<String, Object> map){
		return sysRegionDao.queryList(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return sysRegionDao.queryTotal(map);
	}
	
	@Override
	public void save(SysRegionEntity sysRegion){
		sysRegionDao.save(sysRegion);
	}
	
	@Override
	public void update(SysRegionEntity sysRegion){
		sysRegionDao.update(sysRegion);
	}
	
	@Override
	public void delete(Integer regionId){
		sysRegionDao.delete(regionId);
	}
	
	@Override
	public void deleteBatch(Integer[] regionIds){
		sysRegionDao.deleteBatch(regionIds);
	}

	@Override
	public List<SysRegionEntity> queryRegionList(String parentId) {
		return sysRegionDao.queryRegionList(parentId);
	}

	@Override
	public List<SysRegionEntity> getCregionlist() {
		List<SysRegionEntity> list =  sysRegionDao.getCregionlist();
		return list;
	}

	@Override
	public List<SysRegionEntity> getCregionDetailInfo(String regionId) {
		SysRegionEntity sre =  sysRegionDao.getCregionDetailInfo(regionId);
		List<SysRegionEntity> result = new ArrayList<SysRegionEntity>();
		if(sre != null){
					
			if("北京市".equals(sre.getRegionName()) || "上海市".equals(sre.getRegionName()) || "重庆市".equals(sre.getRegionName()) || "天津市".equals(sre.getRegionName())){
				result= sysRegionDao.getCSpecialregionDetailInfo(regionId);
			}else{
				result= sysRegionDao.getCCommonialregionDetailInfo(regionId);
			}
		}
		String _regionCode = "";
		for (SysRegionEntity sysRegionEntity : result) {//获取区下的商圈列表
			_regionCode = String.valueOf(sysRegionEntity.getRegionId());
			Map<String,Object> map = new HashMap<String, Object>();
			map.put("regionCode", _regionCode);
			List<BusinessCircleEntity>  listBusinessCircleEntity = businessCircleDao.queryList(map);
			sysRegionEntity.setListBusinessCircleEntity(listBusinessCircleEntity);
		}
		return result;
	}
}
